﻿using System;
using nRoute.Components.Composition;
using nRoute.Controllers;
using nRoute.Controllers.Mapping;
using nRoute.Samples.OfficerXcel.Services;

namespace nRoute.Samples.OfficerXcel.Controllers
{
    [MapController("Worksheet/Active/{action}")]
    public class ActiveWorksheetController
        : Controller
    {
        private readonly IActiveWorksheetService _activeWorksheetService;
        
        [ResolveConstructor]
        public ActiveWorksheetController(IActiveWorksheetService activeWorksheetService)
        {
            if (activeWorksheetService == null) throw new ArgumentNullException("activeWorksheetService");
            _activeWorksheetService = activeWorksheetService;
        }

#region Methods

        public void NewWorksheet()
        {
            _activeWorksheetService.NewWorksheet();
        }

        public void OpenWorksheet()
        {
            _activeWorksheetService.OpenWorksheet();
        }

        public void SaveWorksheet()
        {
            if (_activeWorksheetService.ActiveWorksheet != null) _activeWorksheetService.SaveWorksheet();
        }

        public void CloseWorksheet()
        {
            if (_activeWorksheetService.ActiveWorksheet != null) _activeWorksheetService.CloseActiveWorksheet();
        }

#endregion

    }
}
